﻿Public Class FormStandingBook
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim txt As TextBox
    Dim objMstTechnology As New clsMstTechnology
    Dim objStandingBook As New clsStandingBook
    Dim update_status As String = "INSERT_TYPE"
    Dim en As entityStandingBook
    Dim _sys_id As String

    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property
    Private Sub FormStandingBook_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS2", "", g_jsInitFileName)
        txtOperDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtOperDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub initForm()
        Dim dtMstTechnology As DataTable = objMstTechnology.getListByName(Me.Text)
        If dtMstTechnology.Rows.Count > 0 Then
            txtId.Text = dtMstTechnology.Rows(0)("sys_id").ToString()
            txtRequirement.Text = dtMstTechnology.Rows(0)("requirement").ToString()
        End If
        Dim TDate As String = Date.Now.ToShortDateString()
        txtDate.Text = TDate
        txtOperDate.Text = Date.Now.ToString()
        txt_paint_brand.Text = String.Empty
        txt_primer_count.Value = 0
        txt_primer_curing_agent_count.Value = 0
        txt_topcoat_count.Value = 0
        txt_topcoat_curing_agent_count.Value = 0
        txt_medium_paint_curing_agent_count.Value = 0
        txt_medium_paint_count.Value = 0
        txt_spot_inspector.Text = usr
        txt_confirmer.Text = usr
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objStandingBook.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txtRequirement.Text = row("requirement")
            txtId.Text = row("technology_id")
            txt_paint_brand.Text = row("paint_brand")
            txtOperDate.Text = row("oper_date")
            txtDate.Text = row("prod_date")
            txt_primer_count.Text = row("primer_count")
            txt_primer_curing_agent_count.Text = row("primer_curing_agent_count")
            txt_topcoat_count.Text = row("topcoat_count")
            txt_topcoat_curing_agent_count.Text = row("topcoat_curing_agent_count")
            txt_medium_paint_curing_agent_count.Text = row("medium_paint_curing_agent_count")
            txt_medium_paint_count.Text = row("medium_paint_count")
            txt_spot_inspector.Text = row("spot_inspector")
            txt_confirmer.Text = row("confirmer")
        End If
    End Sub

    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_primer_count.MouseDown, txt_primer_curing_agent_count.MouseDown, txt_topcoat_count.MouseDown, txt_topcoat_curing_agent_count.MouseDown, txt_medium_paint_curing_agent_count.MouseDown, txt_medium_paint_count.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub txt_MouseClick(sender As Object, e As MouseEventArgs) Handles txtDate.MouseClick
        txt = CType(sender, TextBox)
        DateNavigator1.Left = txt.Left
        DateNavigator1.Top = txt.Location.Y + txt.Height
        DateNavigator1.Visible = True
    End Sub


    Private Sub DateNavigator1_DateTimeChanged(sender As Object, e As EventArgs) Handles DateNavigator1.DateTimeChanged
        txt.Text = DateNavigator1.DateTime.ToShortDateString()
        DateNavigator1.Visible = False
    End Sub


    Private Sub setEntity()
        en = New entityStandingBook
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .technology_id = txtId.Text
            .oper_date = txtOperDate.Text
            .prod_date = txtDate.Text
            .paint_brand = txt_paint_brand.Text
            .primer_count = txt_primer_count.Text
            .primer_curing_agent_count = txt_primer_curing_agent_count.Text
            .topcoat_count = txt_topcoat_count.Text
            .topcoat_curing_agent_count = txt_topcoat_curing_agent_count.Text
            .medium_paint_count = txt_medium_paint_count.Text
            .medium_paint_curing_agent_count = txt_medium_paint_curing_agent_count.Text
            .spot_inspector = txt_spot_inspector.Text
            .confirmer = txt_confirmer.Text
        End With
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择生产日期", vbYes, "提示")
            Exit Sub
        End If
        If String.IsNullOrEmpty(txtOperDate.Text.Trim()) Then
            MsgBox("请选择操作日期", vbYes, "提示")
            Exit Sub
        End If
        If String.IsNullOrEmpty(txt_paint_brand.Text.Trim()) Then
            MsgBox("请填写水漆品牌", vbYes, "提示")
            Exit Sub
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objStandingBook.insert(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                initForm()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objStandingBook.update(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                CType(Owner, FormStandingBookRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub

End Class

Public Class entityStandingBook
    Public sys_id As String
    Public factory_id As String
    Public technology_id As String '工艺ID
    Public oper_date As String '操作日期
    Public prod_date As String '生产日期
    Public paint_brand As String '水漆品牌
    Public primer_count As String '底漆空桶(个)
    Public primer_curing_agent_count As String '底漆固化剂空桶(个)
    Public topcoat_count As String '面漆空桶(个)
    Public topcoat_curing_agent_count As String '面漆固化剂桶(个)
    Public medium_paint_count As String '中漆空桶(个)
    Public medium_paint_curing_agent_count As String '中漆固化剂空桶(个)
    Public spot_inspector As String '点检人
    Public confirmer As String '确认人
End Class